package com.huike.controller.course;

import com.huike.dto.CoursePagDTO;
import com.huike.result.PageResult;
import com.huike.result.Result;
import com.huike.service.Statistics.course.CourseService;
import com.huike.vo.Course;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/clues/course")
@Slf4j
@Api(tags = "课程管理相关接口")
public class CourseController {
    @Autowired
    private CourseService courseService;
    @GetMapping("/list")
    @ApiOperation("课程查询")
    public PageResult courseList(CoursePagDTO dto){
        log.info("课程查询参数=-==={}",dto);
        return courseService.selectCourseList(dto);
    }

    @DeleteMapping("/{ids}")
    @ApiOperation("课程删除")
    public Result<String> delete(@PathVariable(value = "ids") List<Integer>ids){
        courseService.delete(ids);
        Result<String> success = Result.success();
        success.setMsg("操作成功");
        return success;
    }
    @PostMapping
    @ApiOperation("课程新增")
    public Result<String> save(@RequestBody Course course){
        courseService.save(course);
        return Result.success();
    }
    @GetMapping("/{id}")
    @ApiOperation("根据id查询课程")
    public Result<Course> courseSelectById(@PathVariable("id") Long id){
        Course course = courseService.SelectCourseById(id);
        return Result.success(course);
    }
    @PutMapping
    @ApiOperation("课程修改")
    public Result<String> courseUpdate(@RequestBody Course course){
        courseService.Upddate(course);
        return Result.success();
    }

    @GetMapping("/listselect")
    @ApiOperation("全部课程查询")
    public Result<List<Course>> courseSelectList(){
        List<Course>list = courseService.SelectCourseList();
        return Result.success(list);
    }
}
